#ifndef STOCK_INFO_WIDGET_HPP
#define STOCK_INFO_WIDGET_HPP

#include "market_data_manager.hpp"
#include "stock.hpp"
#include "tools/stock_table_delegate.hpp"
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
#include <QVBoxLayout>
#include <QWidget>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>

QT_CHARTS_USE_NAMESPACE

class StockInfoWidget : public QWidget {
  Q_OBJECT

public:
  explicit StockInfoWidget(MarketDataManager *marketManager,
                           QWidget *parent = nullptr);

  QTableView *getStockTableView() const;

public slots:
  void onMarketUpdated();
  void showStockChart(const QString &stockCode);

signals:
  void stockSelected(const QString &stockCode, const QString &stockName,
                     double price);

private:
  void setupUI();
  void setupConnections();
  void refreshStockTable();

private:
  MarketDataManager *m_marketManager;
  QTableView *m_stockTableView;
  QStandardItemModel *m_stockModel;
  StockTableDelegate *m_stockDelegate;
  QPushButton *m_refreshButton;

  // 图表相关
  QChartView *m_chartView;
  QChart *m_chart;
  QString m_currentStockCode;
};

#endif // STOCK_INFO_WIDGET_HPP
